//选房填表页面控制器
app.controller("name", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	scrollTo(0, 0);
	var userID = localStorage.getItem("user_ID")
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'House/choice',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
	}).success(function(data) {
		console.log(data)
		$scope.areas = data["list"]["area"]
		$scope.city = data["list"]["city"]
		$scope.firstPay = data["list"]["first"]
		$scope.house = data["list"]["house"]
		$scope.prices = data["list"]["prices"]
		$scope.project = data["list"]["project"]
		$scope.use = data["list"]["use"]
	})
	//点击切换效果
	$(".icon-combinedshapefuben").click(function() {
		var flag = $(this).hasClass('active');
		if(!flag) {
			$(this).addClass('active');	
			$(this).addClass("icon-jiantouxia").removeClass("icon-combinedshapefuben");
			$(this).parents(".name").find(".name_ul").slideDown();
		} else {
			$(this).removeClass('active');
			$(this).addClass("icon-combinedshapefuben").removeClass("icon-jiantouxia");
			$(this).parents(".name").find(".name_ul").slideUp()
		}
	})
	setTimeout(function() {
		$(".name_ul li span").click(function() {
			var val = $(this).html()
			var id = $(this).attr("data-info")
			$(this).parent("li").addClass("li_active").siblings().removeClass("li_active")
			$(this).parent().parent().parent(".name").find("input").val(val).attr("data-info",id)
		})
	}, 200)
	//选择地址插件
	var selectArea4 = new MobileSelectArea();
	selectArea4.init({
		trigger: '#txt_area',
		value: $('#txt_area').val(),
		data: []
	});
	$.get('js/areaJson_upd0427.json', function(result) {
		selectArea4.settings.data = result.data;
		selectArea4.data = result.data;
	})
	$(".btn").click(function() {
		var username = $(".userName").val() //用户名
		var userTel = $(".userTel").val() //手机号
		var card = $(".Card").val() //身份证
		var city_id = $(".city_id").attr("data-info") //城市      id
		var addr = $(".address").val() //详细地址
		var house_id = $(".house_id").attr("data-info") //户型      id
		var area_id = $(".area_id").val() //面积
		var project_id = $(".project_id").attr("data-info") //项目     id
		var price_id = $(".price_id").val() //价格
		var first_pay = $(".first_pay").val() //首付
		var use_id = $(".use_id").attr("data-info") //用途    id
		var province = localStorage.getItem("province") //省
		var city = localStorage.getItem("city") //市
		var district = localStorage.getItem("district") //区
		if(!username || !userTel || !city_id || !addr || !house_id || !area_id || !project_id || !price_id ||!first_pay || !use_id) {
				$(".addressdialog").show();
				$(".addressdialog").html("信息填写不全");
				$(".addressdialog").fadeOut(1200);
		} else {
			$http({
				method: 'post',
				url: '' + $rootScope.Location + 'Submit/choos_house',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: {
					card:card,
					user_Id: userID,
					city_Id: city_id,
					house_Id: house_id,
					project_Id: project_id,
					addr: addr,
					prices: price_id,
					payment: first_pay,
					uses: use_id,
					area: area_id,
					tel: userTel,
					username: username,
					province: province,
					city: city,
					district: district
				}
			}).success(function(data) {
				$(".addressdialog").show();
				$(".addressdialog").html(data["message"]);
				$(".addressdialog").fadeOut(1200);
				setTimeout(function(){
					$state.go("main.home")
				},1200)
			})
		}
	})
}])
app.controller("serListinfo", ["$scope", "$rootScope", "$stateParams", "$state", "$http", function($scope, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'home';
	$rootScope.page.goshow = true
	$scope.num = $stateParams.num
	$scope.clickZan = function(Data,Location,data){   //封装点赞功能
		$scope.zan = function() {
			if($scope.is_like == 0) {
				$http({
					method: 'post',
					url: '' + $rootScope.Location +Location+'' ,
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data
				}).success(function(Data) {
					$scope.like++
					$scope.is_like++
				})
			} else{
				$http({
					method: 'post',
					url: '' + $rootScope.Location + Location+'',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data
				}).success(function(Data) {
					$scope.like--
					$scope.is_like--
				})
			}

		}
	}
	if($stateParams.num == 6){
		$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Message/qy_detail',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			Id: $stateParams.id
		}
	}).success(function(Data) {
		var id = Data["list"]["news_Id"]
		var data = {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			news_Id: id
		}	
		$scope.list = Data["list"]
		$scope.like = Data["list"]["like"]
		$scope.is_like = Data["list"]["is_like"]
		$rootScope.page.goshow = false
		$scope.clickZan(Data,'Message/new_like',data)		
	})
	}
	if($stateParams.num==4){
		$http({
		method: 'post',
		url: '' + $rootScope.Location + 'master/detail',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			Id: $stateParams.id
		}
		}).success(function(Data) {
			$rootScope.page.goshow = false
			$scope.list = Data["list"]
			$scope.like = Data["list"]["likes"]
			$scope.is_like = Data["list"]["is_like"]
			var id = Data["list"]["Id"]
			var data = {
				user_Id: localStorage.getItem("user_ID"),
				token: localStorage.getItem("token"),
				master_Id: id
			}	
			$scope.clickZan(Data,"master/master_like",data)
		})
	}
	if($stateParams.num==3){
		$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Picture/headline',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			Id: $stateParams.id
		}
		}).success(function(Data) {
			console.log(Data)
			$rootScope.page.goshow = false
			$scope.list = Data["list"]
			$scope.like = Data["list"]["likes"]
			$scope.is_like = Data["list"]["is_like"]
//			var id = Data["list"]["Id"]
//			var data = {
//				user_Id: localStorage.getItem("user_ID"),
//				token: localStorage.getItem("token"),
//				master_Id: id
//			}	
//			$scope.clickZan(Data,"master/master_like",data)
		})
	}
}])

//轮播图外链
app.controller("new_info", ["$scope", "$rootScope","$stateParams","$state","$http",function($scope, $rootScope, $stateParams, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'home';
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'News/new_detail',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			id: $stateParams.id
		}
		}).success(function(Data) {
			console.log(Data)
			$scope.list = Data["list"]
			$scope.like = Data["list"]["like"]
			$scope.is_like = Data["list"]["is_like"]
		})
}])